package com.wechat.api.rpc;

import com.wechat.api.to.ReturnObjectTO;
import com.wechat.api.util.HttpClientUtil;
import com.wechat.api.util.JsonUtil;
import com.wechat.api.util.TokenUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * Created by Liumh on 2018/4/11.
 */
public class UserRPC {

    @Value("${wx_list_openid_url}")
    private String listOpenIdURL;

    /**
     * 获取用户列表
     * @return
     */
    @RequestMapping("allopenid")
    public ReturnObjectTO getAllOpenId(){
        ReturnObjectTO result = ReturnObjectTO.success();
        try{
            String token = TokenUtil.getAccessToken();    //获取token值
            System.out.println(token);
            String doget = HttpClientUtil.doGet(listOpenIdURL+"?access_token="+token+"&next_openid=");
            Map<String, String> map = JsonUtil.fromJson(doget, Map.class);
            result.put("wx",map);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
}
